    var base_path = "http://music.tmradio.net/api/status.js?var=data&callback=tm_callback&";
    var script_id = "tmradio_status";
    var curr_status = {};
    var last_voted = 0;
    var vote_blocked = false;
    function update_status(){
    //console.log('updating chat from id: '+_lastId);
        var e=document.getElementById(script_id); 
        if (e!=undefined) {e.parentNode.removeChild(e);};
        scriptId = "tmradio_status"+Math.random().toString().replace(/\./g,"");
        var url = base_path+"&"+scriptId;
        var head_element = document.getElementsByTagName("head")[0]; 
        var script = document.createElement('script');
        script.id = scriptId; 
        script.type = "text/javascript"; 
        script.src = url; 
        head_element.appendChild(script);
    };
    function tm_callback(data) {
        if (curr_status.id != data.id) {unblock_vote(); };
        curr_status = data;
        var status_text = "";
        status_text += data.title + " by " + data.artist;
        var q = 'http://www.lastfm.ru/music/' + data.artist.replace(/\s/g,'%20');
        var a_text = '<a href="' + q + '" title="Искать исполнителя на LastFm">' + data.artist + '</a>';
        q += '/_/'+data.title.replace(/\s/g,'%20');
        a_text = '<a href="'+q+'" title="Искать композицию на LastFm">' + data.title + '</a> by ' + a_text;
        document.getElementById('tm_status_text').innerHTML = a_text;

        var track_info = "Рейтинг песни "+data.weight.toPrecision(3);
        track_info += ", длина "+Math.floor(data.length/60)+':';
        if ( (data.length%60)<10 ) track_info+='0'; track_info += Math.round(data.length%60);
        track_info += ", проигрываний "+data.count+'.';
        var tags = "";
        for (i=0; i<data.labels.length; i+=1) {
            label = data.labels[i];
            if (label == 'tagme') label = "<b>tagme</b>";
            if (tags.length > 0) label = ", "+label;
            if (label.indexOf(':')<0) tags += label;
        }
        if (tags.length>0) track_info += " Теги: "+tags;
        document.getElementById('track_info').innerHTML = track_info;
    };
    function send_vote(vote) {
        if (vote_blocked) return false;
        block_vote();
        track_id = curr_status.id;
        if (track_id == last_voted) {
            alert("Вы уже проголосовали за эту песню!");
            return false;
            };            
        $.ajax({
            url: "/tmradio/vote/"+track_id+"/"+vote,
            success: function(data){
                last_voted = track_id;
                if (data == 'ok') {
                    show_message('Ваш голос отправлен!');
                    update_status();
                } else if (data == 'already voted') {
                    show_message('Вы уже голосовали за эту песню');
                } else {
                    show_message('Какая-то ошибка... ('+data+')');
                    unblock_vote();
                };
            }

        });
    };
    function block_vote() {
        vote_blocked = true;
        $('#vote_rocks').addClass('blocked');
        $('#vote_sucks').addClass('blocked');
    };
    function unblock_vote() {
        vote_blocked = false;
        $('#vote_rocks').removeClass('blocked');
        $('#vote_sucks').removeClass('blocked');

    }
    var status_updater = window.setInterval(update_status, 20000);
    function show_message(text) {
        fade_message(text);
        setTimeout(hide_message, 3000);
    };
    function fade_message(text) {
        $('#vote_result').html(text);
        $('#vote_result').fadeIn('slow');
    };
    function hide_message() { $('#vote_result').fadeOut('slow'); };

